package com.hkts.naturalgas.instrumentdata.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.instrumentdata.entity.HontLog;
import com.hkts.naturalgas.instrumentdata.mapper.HontLogMapper;
import com.hkts.naturalgas.instrumentdata.service.IHontLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2020-07-28
 */
@Service
@Transactional
public class HontLogServiceImpl extends ServiceImpl<HontLogMapper, HontLog> implements IHontLogService {


@Autowired
private HontLogMapper hontLogMapper;

@Override
public IPage<HontLog> selectPage(Page<HontLog> page, HontLog hontLog){
        QueryWrapper<HontLog> query = Wrappers.query();
        QueryWrapper<HontLog> entityWrapper = getEntityWrapper(query, hontLog);
        return hontLogMapper.selectPage(page, entityWrapper);
        }




@Override
public List<HontLog> selectList(HontLog hontLog){
        QueryWrapper<HontLog> query = Wrappers.query();
        QueryWrapper<HontLog> entityWrapper = getEntityWrapper(query, hontLog);
        return hontLogMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<HontLog> getEntityWrapper(QueryWrapper<HontLog> entityWrapper,HontLog hontLog){
        //条件拼接

                if(StringUtils.isNotBlank(hontLog.getIp())){
                entityWrapper.like(HontLog.IP,hontLog.getIp());
                }
                if(StringUtils.isNotBlank(hontLog.getIpInfo())){
                entityWrapper.like(HontLog.IP_INFO,hontLog.getIpInfo());
                }

                if(StringUtils.isNotBlank(hontLog.getName())){
                entityWrapper.like(HontLog.NAME,hontLog.getName());
                }
                if(StringUtils.isNotBlank(hontLog.getRequestParam())){
                entityWrapper.like(HontLog.REQUEST_PARAM,hontLog.getRequestParam());
                }
                if(StringUtils.isNotBlank(hontLog.getRequestType())){
                entityWrapper.like(HontLog.REQUEST_TYPE,hontLog.getRequestType());
                }
                if(StringUtils.isNotBlank(hontLog.getRequestUrl())){
                entityWrapper.like(HontLog.REQUEST_URL,hontLog.getRequestUrl());
                }
                if(StringUtils.isNotBlank(hontLog.getUsername())){
                entityWrapper.like(HontLog.USERNAME,hontLog.getUsername());
                }

        return entityWrapper;
        }
        }
